<template>
	<view class="mobile-item-container">
    <Navbar :title="title" bgColor="#fff" :h5Show="true"></Navbar>
		<view style="padding: 16px 0 10px;">
		  <u-search v-model="params.title" :show-action="true" actionText="查询" @custom="handleSearch" @search="handleSearch"  :animation="true" shape="square" height="40px"></u-search>
		</view>
		<u-tabs :list="tabList" @click="click" :current="0">
		</u-tabs>
		
		<view v-if="list && list.length > 0">
		  <u-cell v-for="(item, index) in list" :key="index" :isLink="true" :border="true" @click="searchDetail(item.detailId)">
		    <view slot="title" class="notice-record-title">{{item.title}}</view>
		    <view slot="label" class="notice-record-desc">
		      <view style="display: flex; margin-left: 16px;">
		        <u-icon name="clock" size="12"></u-icon>
		        <text>{{item.releaseTime}}</text>
		      </view>
		      <view style="display: flex; margin-left: 16px;">
		        <u-icon name="tags" size="12"></u-icon>
		        <text>{{item.columnName}}</text>
		      </view>
		    </view>
		  </u-cell>
		</view>
		<u-empty v-else></u-empty>
		
	</view>
</template>

<script>
	import Navbar from '@/components/navbar/Navbar'
	import FloatButton from '@/components/button/FloatButton'

	import * as detailApi from '@/api/business/detail'
	export default {
		components: {
		  Navbar,FloatButton
		},
		data() {
			return {
				title: '我的发布',
				list: [],
				params: {
				  pageNum: 0,
				  pageSize: 10,
				  title: '',
				  state: ''
				},
				tabList: [{
					name: '全部',
				}, {
					name: '草稿',
				}, {
					name: '已发布'
				}]
			}
		},
		mounted() {
		    const app = this;
		    uni.$on('update', function(data) {
		        app.handleSearch()
		    })
		},    
		//为了优化代码，可以加上移除事件，避免重复监听事件
		onUnload() {
		    // 移除监听事件  
		    uni.$off('update');
		},
		onLoad () {
		  this.loadData()
		},  
		methods: {
			click(item) {
				this.params.title = ''
				this.params.state = ''
				if(item.index == 1){
					this.params.state = 'N'
				}else if(item.index == 2){
					this.params.state = 'Y'
				}
				this.handleSearch()
			},
			handleSearch(){
				this.params.pageNum = 0;
				this.loadData()
			},
			scrolltolower () {
			  this.loadData();
			},
			loadData(){
				this.params.pageNum += 1;
				detailApi.getUserList(this.params).then(res => {
					this.list = res.rows;
				})
			},
			searchDetail(id){
				uni.navigateTo({ url: '/pages/business/columnDetail/detail?id=' + id})
			}
		}
	}
</script>

<style>

</style>